class ColorsController < ApplicationController
  def index
    list
    render :action => 'list'
  end

  # GETs should be safe (see http://www.w3.org/2001/tag/doc/whenToUseGet.html)
  verify :method => :post, :only => [ :destroy, :create, :update ],
         :redirect_to => { :action => :list }

  def list
    @color_pages, @colors = paginate :colors, :per_page => 10
  end

  def show
    @color = Color.find(params[:id])
  end

  def new
    @color = Color.new
  end

  def create
  if params[:color][:second]
   	@color = DualScheme.new(params[:color])
   else
   	@color =MonoScheme.new(params[:color])
   end
    if @color.save
     flash[:notice] = 'Color was successfully created.'
      redirect_to :action => 'list'
    else
     render :action => 'new'
   end
  end

  def edit
    @color = Color.find(params[:id])
  end

  def update
    @color = Color.find(params[:id])
     if params[:color][:second]
   	@color[:type] = "DualScheme"
   	end
    if @color.update_attributes(params[:color])
      flash[:notice] = 'Color was successfully updated.'
      redirect_to :action => 'show', :id => @color
    else
      render :action => 'edit'
    end
  end

  def destroy
    Color.find(params[:id]).destroy
    redirect_to :action => 'list'
  end
end
